<?php

// 
// this looks up the TED talk ID based on the filename of the flash file
// this is done with a lookup index generated from a shell script
// transparently passes short ids and returns null (in a JS object) if the page pulls a 404
// if the page isn't found, returns an empty string
//
// Sample call:  http://joemaller.com/services/ted_lookup.php?ted=MICHAELSHERMER_high.flv&callback=?   (jQuery adds the callback)
//
// Can also use IDs:
// 
// Sample call:  http://joemaller.com/services/ted_lookup.php?ted=22&callback=?   (jQuery adds the callback)


# set up timer variables
$time = explode(" ", microtime()); 
$stime = $time[1] . substr($time[0],1,strlen($time[0])); 

$index = htmlspecialchars($_GET['ted']);

include("$_SERVER[DOCUMENT_ROOT]/services/tedtalks.php");

$time2 = explode (" ",microtime ()); 
$etime = $time2[1] . substr($time2[0],1,strlen($time2 [0])); 

echo htmlspecialchars(
	$_GET['callback']) 
	. '({ "_id":"' . $TED[$index]['id'] 
	. '", "_mp4":"' . $TED[$index]['mp4'] 
	. '", "_img":"' . $TED[$index]['jpg'] 
	. '", "_page":"' . $TED[$index]['page'] 
	. '", "_duration":"' . $TED[$index]['duration'] 
	. '", "_title":"' . htmlspecialchars($TED[$index]['title']) 
	. '", "execution_time":' . round($etime - $stime,4) 
	. ' })';

?>
